<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let loginList = [
        { userName: 'admin', password: 'admin321' },
        { userName: 'zhangsan', password: 'zs321' },
        { userName: 'lisi', password: 'ls321' },
        { userName: 'yyqx', password: 'yyqx321' },
      ]

      let userInfo = {
        token1: {
          city: '杭州',
          money: '1000w',
          sex: '女',
          userName: 'admin',
          password: 'admin321',
        },
        token2: {
          city: '北京',
          money: '1100w',
          sex: '女',
          userName: 'zhangsan',
          password: 'zs321',
        },
        token3: {
          city: '北京',
          money: '800w',
          sex: '男',
          userName: 'lisi',
          password: 'ls321',
        },
        token4: {
          city: '天津',
          money: '600w',
          sex: '男',
          userName: 'yyqx',
          password: 'yyqx321',
        },
      }
      let sunm = function () {
        let count = 3
        while (true) {
          let una = prompt('请输入用户名')
          let pad = prompt('请输入密码')
          for (let i = 0; i < loginList.length; i++) {
            if (
              una === loginList[i].userName &&
              pad === loginList[i].password
            ) {
              let sum = Math.floor(Math.random() * 4) + 1
              let sum1 = 'token' + sum
              for (let k in userInfo) {
                if (k === sum1) {
                  alert(`用户登录成功:
                  城市:${userInfo[k].city}
                  钱:${userInfo[k].money}
                  性别:${userInfo[k].sex}
                  姓名:${una}`)
                  count--
                  return
                }
              }
            } else {
              let failure = +prompt(`
                 1.注册
                 2.直接退出
                 `)
              if (failure === 1) {
                let userName1 = prompt('请输入用户名')
                let password1 = prompt('请输入密码')
                loginList.push({ userName: userName1, password: password1 })
                console.log(loginList)
                alert('注册成功，快去登录')
                let na = prompt('请输入用户名')
                let pass = prompt('请输入密码')
                for (let i = 0; i < loginList.length; i++) {
                  if (
                    na === loginList[i].userName &&
                    pass === loginList[i].password
                  ) {
                    let sum = Math.floor(Math.random() * loginList.length) + 1
                    let sum1 = 'token' + sum
                    for (let k in userInfo) {
                      if (k === sum1) {
                        alert(`用户登录成功:
                  城市:${userInfo[k].city}
                  钱:${userInfo[k].money}
                  性别:${userInfo[k].sex}
                  姓名:${userName1}`)
                        count--
                        return
                      }
                    }
                  }
                }
              } else if (failure === 2) {
                return
              }
            }
          }
          if (!count) return alert('没机会了')
        }
      }

      sunm()
    
    </script>
  </body>
</html>
